package cn.ronghuanet.base.service.impl;

import cn.ronghuanet.base.mapper.BaseMapper;
import cn.ronghuanet.base.query.BaseQuery;
import cn.ronghuanet.base.service.IBaseService;
import cn.ronghuanet.base.util.PageInfo;
import cn.ronghuanet.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public T selectById(Serializable id) {
        return mapper.selectById(id);
    }

    @Override
    public List<T> selectAll() {
        return mapper.selectAll();
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }
    @Transactional
    @Override
    public void delete(Serializable id) {
        mapper.delete(id);
    }
    @Transactional
    @Override
    public void insert(T o) {
        mapper.insert(o);
    }

    @Override
    public PageInfo pageList(BaseQuery baseQuery) {
        // 查询总条数
        Long total = mapper.countTotal(baseQuery);
        if (total > 0) {
            // 分页查询
            List<T>  list = mapper.queryPageList(baseQuery);
            return new PageInfo<>(total,list);
        }
        // 封装数据
        // 返回数据
        return new PageInfo<T>();
    }

    @Override
    public void batchDelete(List ids) {
        mapper.batchDelete(ids);
    }
}
